//
//  YFMyGiftCell.m
//  project
//
//  Created by yefei on 2019/4/15.
//  Copyright © 2019 健健. All rights reserved.
//

#import "YFMyGiftCell.h"
#import "YFMyRecivedGiftModel.h"

@interface YFMyGiftCell ()
@property (weak, nonatomic) IBOutlet UILabel *gitCountLabel;
@property (weak, nonatomic) IBOutlet UIImageView *giftImageView;
@property (weak, nonatomic) IBOutlet UILabel *giftNameLabel;
@property (weak, nonatomic) IBOutlet UIButton *selectedButton;

@end

@implementation YFMyGiftCell

- (void)setModel:(YFMyRecivedGiftModel *)model {
    _model = model;
    self.gitCountLabel.text = model.amount;
    self.giftNameLabel.text = model.name;
    [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:nil];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (IBAction)selectedButtonClicked:(UIButton *)sender {
    sender.selected = !sender.selected;
    _giftIsSelected = sender.selected;
    UIImage *image = [UIImage imageNamed: sender.selected ? @"icon_gift_selected" : @" icon_gift_unselected"];
    [sender setImage:image forState:(UIControlStateNormal)];
    
    if (_selectedAction) {
        _selectedAction(sender.selected, _model.giftId, _model.amount, _model.price);
    }
}

- (void)setGiftIsSelected:(BOOL)giftIsSelected {
    _giftIsSelected = giftIsSelected;
    self.selectedButton.selected = giftIsSelected;
    UIImage *image = [UIImage imageNamed: giftIsSelected ? @"icon_gift_selected" : @" icon_gift_unselected"];
    [self.selectedButton setImage:image forState:(UIControlStateNormal)];
}

@end
